package com.sec.android.app.myfiles.module.download.cmd;

import com.sec.android.app.myfiles.dialog.ConfirmNotExistFileDialog;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.module.download.DownloadFileRecord;

import org.puremvc.java.multicore.interfaces.INotification;
import org.puremvc.java.multicore.patterns.command.SimpleCommand;

public class DownloadConfirmCmd extends SimpleCommand {

    @Override
    public void execute(INotification notification) {
        Object[] params = (Object[]) notification.getBody();

        // Context context = (Context) params[0];
        AbsMyFilesFragment fragment = (AbsMyFilesFragment) params[1];
        DownloadFileRecord record = (DownloadFileRecord) params[2];

        showConfirmDlg(fragment, record);

    }

    private void showConfirmDlg(AbsMyFilesFragment fragment, DownloadFileRecord record) {
        try {
            ConfirmNotExistFileDialog confirmDialog = ConfirmNotExistFileDialog.getInstance(record, fragment);
            if (fragment != null) {
                confirmDialog.showAllowingStateLoss(fragment.getFragmentManager(), "confirm_delete");
                confirmDialog.setTargetFragment(fragment, 0);
            }
        } catch (IllegalStateException e) {
            Log.e(this, "IllegalStateException:" + e.toString());
        }
    }
}
